<template>
  <div class="openclass-list maxW">
    <!-- 单级 联动选择-->
    <template v-if="!isMulti">
      <singleCascader @resChosed="resChosed"></singleCascader>
    </template>
    <!-- 多级 联动选择 -->
    <template v-else>
      <multiCascader
        type="video"
        @resChosed="resChosed"
      ></multiCascader>
    </template>
    <div class="carousel-part clear">
      <div class="caurse-carousel fl">
        <template v-if="carouselPicData.length">
          <el-carousel
            :interval="5000"
            height="400px"
          >
            <el-carousel-item
              v-for="item in carouselPicData"
              :key="item.id"
            >
              <a
                :href="item.link_url == '' ? false : item.link_url"
                :target="item.link_url == '' ? '_Self' : '_Blank'"
              ><img :src="BASE_URL + item.picture" /></a>
            </el-carousel-item>
          </el-carousel>
        </template>
      </div>
      <div class="popularity-list fr">
        <el-card
          class="box-card"
          shadow="never"
        >
          <div
            slot="header"
            class="clearfix"
          >
            <span class="humantitle">人气</span>
          </div>
          <template v-if="humanQiData.length">
            <div
              v-for="(item, index) in humanQiData"
              :key="item.id"
              class="text item humanItem"
            >
              <i :class="[index + 1 < 4 ? 'humanNun yellowC' : 'humanNun']">{{
                index + 1
              }}</i>
              <a
                @click="goToDetailPage(item.status_m3u8, item.id)"
                :title="item.video_name"
              >{{ item.video_name }}</a>
            </div>
          </template>
        </el-card>
      </div>
    </div>
    <div class="course-video-con">
      <div class="filter-nav">
        <el-button
          type="text"
          :class="[orderType == 'time' ? 'blueC' : '']"
          @click="toggle_order('time')"
        >
          时间
          <i class="el-icon-sort-down"></i>
        </el-button>
        <i class="cut">|</i>
        <el-button
          type="text"
          :class="[orderType == 'download' ? 'blueC' : '']"
          @click="toggle_order('download')"
        >
          下载
          <i class="el-icon-sort-down"></i>
        </el-button>
        <i class="cut">|</i>
        <el-button
          type="text"
          :class="[orderType == 'fav' ? 'blueC' : '']"
          @click="toggle_order('fav')"
        >
          收藏
          <i class="el-icon-sort-down"></i>
        </el-button>
      </div>
      <ul class="course-video-list clear">
        <li
          class="course-video-li box"
          v-for="(item, index) of videoListData"
          :key="index"
        >
          <div class="video-thumbnail">
            <a @click="goToDetailPage(item.status_m3u8, item.id)">
              <img
                :src="BASE_URL + item.picture"
                :onerror="errorImg"
              />
            </a>
          </div>
          <div class="video-creater-info">
            <a
              @click="goToDetailPage(item.status_m3u8, item.id)"
              :title="item.video_name"
            >{{ item.video_name }}</a>
            <div class="teacher-info">
              <div @click="
                  goToAppModel(
                    'space/resource',
                    item.uid,
                    item.push_code,
                    item.app_code
                  )
                ">
                <img
                  class="acatar_img"
                  :src="BASE_URL + item.avatar_path"
                  alt="头像"
                />
                <span
                  class="teacher-name"
                  :title="item.user_name"
                >{{
                  item.user_name
                }}</span>
              </div>
              <div>
                <i class="el-icon-video-play"></i>
                <strong>{{ item.clicks }}</strong>
              </div>
            </div>
            <div
              class="category"
              v-if="item.category"
            >
              <span :title="item.category">{{ item.category }}</span>
            </div>
          </div>
          <i
            v-if="item.is_nice == 1"
            class="is-nice"
          ></i>
        </li>
      </ul>
      <div class="pageBox">
        <el-pagination
          v-if="total_number > page_size"
          @current-change="change_page"
          :page-size="page_size"
          :current-page="page_index"
          layout="total,prev, pager, next,jumper"
          :total="total_number"
        ></el-pagination>
      </div>
    </div>
    <div
      class="dependent"
      v-if="placeholder"
    >
      <i class="ipng image_state01"></i>
      <p>还没发现任何相关的公开课哦~</p>
    </div>
  </div>
</template>
<script>
import singleCascader from "@/components/common/single-cascader";
import multiCascader from "@/components/common/multi-cascader";
export default {
  components: {
    singleCascader,
    multiCascader,
  },
  data() {
    return {
      getManagementFlag: false,
      placeholder: false,
      page_index: 1,
      page_size: 16,
      total_number: 0,
      orderType: "time",
      // 单级
      study_section_id: null,
      grade_id: null,
      subject_id: null,
      // 多级
      platform_id: null,
      app_code: "",
      cate_id: null,

      version_id: 0, //版本
      keyword: this.$route.query.keyword, //首页搜索跳转到此页面时带的关键字
      create_id: 0,
      sectionData: [], //学段
      sectionChecked: 0,
      gradeData: [], //年级
      gradeChecked: 0,
      subjectList: [], //科目
      subjectChecked: 0,
      errorImg:
        'this.src="' +
        require("../../../../public/images/image_loding.png") +
        '"',
      checked: false,
      videoListData: [],
      carouselPicData: [],
      humanQiData: [],
    };
  },
  created() {
    this.getCarouselPic();
    this.humanQi();
    this.getVideoData();
  },
  mounted() {
    this.$nextTick(() => {
      this.getCarouselPic();
    });
  },
  computed: {
    isMulti() {
      return this.$store.getters.isMulti;
    },
  },
  watch: {
    "$route.query.keyword"(nv) {
      this.keyword = nv;
      this.getVideoData();
    },
  },
  methods: {
    getVideoData() {
      let success = (res) => {
        this.videoListData = res.data.data;
        this.total_number = parseInt(res.data.data_sum);
        this.page_index = parseInt(res.data.page_index);
        this.placeholder = this.videoListData.length === 0 ? true : false;
      };
      this.$ajax({
        url: "/api/video/video_list",
        method: "get",
        params: {
          page_index: this.page_index,
          page_size: this.page_size,
          study_section_id: this.study_section_id,
          grade_id: this.grade_id,
          subject_id: this.subject_id,
          version_id: this.version_id,
          order_type: this.orderType,
          keyword: this.keyword,
          authority: 1,
          status: 1,
          // 多级
          app_code: this.app_code,
          cate_id: this.cate_id,
        },
        func: { success: success },
      });
    },
    resChosed(obj) {
      // console.log(obj,"选择")
      this.grade_id = obj.grade_id;
      this.subject_id = obj.subject_id;
      this.study_section_id = obj.study_section_id;
      this.platform_id = obj.platform_id;
      this.app_code = obj.school_code;
      this.cate_id = obj.classify_id;
      this.page_index = 1;
      this.getVideoData();
    },
    //轮播图
    getCarouselPic() {
      let success = (res) => {
        this.carouselPicData = deep_clone(res.data);
      };
      this.$ajax({
        url: "api/carousel/banners",
        method: "get",
        params: {
          module: 4,
        },
        func: { success: success },
      });
    },
    //人气
    humanQi() {
      let success = (res) => {
        this.humanQiData = res.data.data;
      };
      this.$ajax({
        url: "/api/video/video_list",
        method: "get",
        params: {
          page_index: 1,
          page_size: 10,
          order_type: "click",
          authority: 1,
          status: 1,
        },
        func: { success: success },
      });
    },
    toggle_order(type) {
      this.orderType = type;
      this.getVideoData();
    },
    change_page(val) {
      this.page_index = val;
      this.getVideoData();
    },
  },
};
</script>
<style lang="scss">
.carousel-part {
  .caurse-carousel {
    display: inline-block;
    width: 860px;
    height: 400px;

    .el-carousel {
      border-radius: 3px;
    }

    .el-carousel__container {
      width: 860px;
    }

    img {
      height: 100%;
    }

    .el-carousel__indicator .el-carousel__button {
      width: 8px;
      height: 8px;
      border-radius: 50%;
    }
  }

  .popularity-list {
    display: inline-block;
    width: 320px;
    background-color: #fff;

    .humantitle {
      padding: 5px 8px;
      border-radius: 2px;
      font-size: 14px;
      color: #fff;
      background-color: #338efc;
    }

    .el-card__header {
      padding: 25px 10px;
      margin: 0 8px;
      border-bottom: solid 2px #e5e5e5;
    }

    .el-card__body {
      height: 299px;
      padding: 15px 20px 20px;
    }

    .humanItem {
      padding: 5px 0;
    }

    .humanItem i {
      border-radius: 4px;
    }

    .humanItem a {
      display: inline-block;
      width: 80%;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }

    .humanItem:hover {
      background-color: #effaff;
    }

    .humanItem:hover > a {
      color: #348efc;
    }

    .humanNun {
      display: inline-block;
      width: 20px;
      height: 20px;
      line-height: 20px;
      text-align: center;
      color: #ffffff;
      background: #d2d2d2;
      margin-right: 10px;
    }

    .humanNun.yellowC {
      background: #f2b732;
    }
  }
}

.course-video-con {
  margin: 20px 0 40px;
}

.filter-nav {
  .el-button {
    font-size: 16px;
    color: #000;
  }

  .el-icon-sort-down {
    margin-left: 5px;
  }

  .cut {
    margin: 0 20px 0 10px;
    color: #d2d2d2;
  }

  .blueC {
    color: #338efc;
  }
}

.course-video-list {
  .course-video-li {
    float: left;
    width: 290px;
    border-radius: 3px;
    box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin: 0 13px 20px 0;
    background: #fff;

    -moz-transition: all 0.35s ease-in;
    -webkit-transition: all 0.35s ease-in;
    -o-transition: all 0.35s ease-in;
    transition: all 0.35s ease-in;
    position: relative;

    .course-video-li .video-creater-info > a,
    .course-video-li .video-creater-info > p {
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }
  }

  .course-video-li:hover {
    -webkit-box-shadow: 0 6px 7px 0 rgba(0, 0, 0, 0.1);
    -moz-box-shadow: 0 6px 7px 0 rgba(0, 0, 0, 0.1);
    box-shadow: 0 6px 7px 0 rgba(0, 0, 0, 0.1);
  }

  .course-video-li .video-thumbnail {
    height: 140px;
    display: block;
    overflow: hidden;
  }

  .course-video-li .video-thumbnail a,
  .course-video-li .video-thumbnail img {
    width: 100%;
    height: 100%;
    vertical-align: top;
  }

  .video-thumbnail a {
    position: relative;
  }

  .video-thumbnail a::after {
    content: "";
    opacity: 0;
    background: linear-gradient(
      180deg,
      rgba(0, 0, 0, 0.01) 2%,
      rgba(0, 0, 0, 0.2)
    );
    transition: opacity 0.4s ease-in-out;
    position: absolute;
    top: 2px;
    left: 0;
    width: 100%;
    height: 140px;
  }

  .video-thumbnail:hover > a:after {
    opacity: 1;
  }

  .course-video-li .video-creater-info {
    padding: 0 10px 20px;
    background: #ffffff;
  }

  .course-video-li .video-creater-info > a {
    font-size: 14px;
    color: #020202;
    line-height: 20px;
    padding-top: 13px;
    display: block;
    cursor: pointer;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .course-video-li .video-creater-info .course-video-li:hover {
    box-shadow: 0 6px 7px 0 rgba(0, 0, 0, 0.1);
  }

  .course-video-li:nth-of-type(4n) {
    margin: 0 0 18px 0;
  }

  .teacher-info {
    margin-top: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    > div {
      // height: 25px;
      // line-height: 25px;
    }
    .teacher-name {
      display: inline-block;
      width: 153px;
      height: 25px;
      line-height: 25px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .acatar_img {
      display: inline-block;
      width: 25px;
      height: 25px;
      -moz-border-radius: 50%;
      border-radius: 50%;
      overflow: hidden;
      margin-right: 5px;
    }
    .el-icon-video-play {
      font-size: 18px;
      color: #b2c5db;
      vertical-align: middle;
    }

    strong {
      margin-left: 5px;
      vertical-align: middle;
    }
  }
  .category {
    padding-top: 15px;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.is-nice {
  position: absolute;
  top: 0;
  right: 0;
  display: inline-block;
  width: 20px;
  height: 20px;
  background: url("../../../assets/images/openclassQuality.png") no-repeat;
}

.dependent {
  background-color: #fff;
  text-align: center;
  overflow: hidden;
  margin-bottom: 50px;
  padding-top: 30px;

  p {
    color: #999;
    margin: 40px 0;
  }
}
</style>